<template>
  <div class="app-container">
    <el-row class="mb8">
      <el-button
        size="small"
        type="primary"
        title="新增"
        @click="addCube(false)"
      >
        <i class="fa fa-plus" aria-hidden="true"></i>新增
      </el-button>
    </el-row>
    <el-table
        :data="tableData"
        @row-click="selectme"
        border>
        <el-table-column label="" width="35" :resizable="false">
          <template slot-scope="scope">
            <el-radio v-model="checked" name="myselect" :label="scope.row.cubeId">&nbsp;</el-radio>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="cubeId"
          label="标识"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="cubeName"
          label="立方体名称"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="desc"
          label="立方体说明"
        ></el-table-column>
        <el-table-column
          align="center"
          prop="dsetName"
          label="数据集"
        ></el-table-column>
      <el-table-column width="170" :resizable="true">
        <template slot-scope="scope">
          <el-button
            size="small"
            type="warning"
            @click="addCube(true,scope.row.cubeId)"
          >
            <i class="el-icon-edit"></i>编辑
          </el-button>
          <el-button
            size="small"
            type="danger"
            @click="delCube(scope.row.cubeId)"
          >
            <i class="el-icon-delete"></i>删除
          </el-button>
        </template>
      </el-table-column>
      </el-table>
    <cubeAdd ref="cubeAdd" :isupdate="isupdate"></cubeAdd>
  </div>
</template>
<script>

import request from "@/utils/request"
import cubeAdd from "@/views/bi/model/cube/cubeAdd";
import Text from "@/views/bi/portal/prop/Text";

export default {
   name: 'cube',
  data() {
    return {
      tableData:[],
      checked:null,
      isupdate:false
    }
  },
  components: {
    Text,
    cubeAdd
	},
  mounted() {
    this.loadData();
  },
  computed: {},
  methods: {
     //加载列表数据
	 loadData(){
      request({
        url:"/bi/model/listCube",
        method:'get'
      }).then(resp=>{
        this.tableData = resp.rows;
      });
    },
    selectme(a, b){
      this.checked = a.cubeId;
    },
    //添加立方体，打开子组件
    addCube(isupdate,cubeId){
      this.isupdate = isupdate;
      this.$refs["cubeAdd"].addCube(cubeId);
    },
    //删除立方体
    delCube(){
      this.$confirm("是否确认删除？","提示",{
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(()=>{
        request({
          url:"/bi/model/delCube",
          method:"delete",
          params:{cubeId:this.checked},
        }).then(resp=>{
          this.$message({
            type:"success",
            message:"删除成功",
            duration:1000
          })
          this.loadData();
        });
      })
    }
  }
};
</script>
